package de.nordakademie.wpk.boerse.ui.editor;

import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.widgets.Table;

/**
 * @author Marcus Berndt
 * 
 */
public class NumberCellEditor extends TextCellEditor {

	/**
	 * 
	 */
	public NumberCellEditor(Table table) {
		super(table);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.viewers.TextCellEditor#doSetValue(java.lang.Object)
	 */
	@Override
	protected void doSetValue(Object value) {
		text.setText(String.valueOf(value));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.viewers.CellEditor#isValueValid()
	 */
	@Override
	public boolean isValueValid() {
		try {
			int value = Integer.valueOf(text.getText());
			if (value < 1)
				return false;
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}
}
